package main

import (
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
	"fmt"
	"gorm_demo/model"
)

func main() {
	db, err := gorm.Open("mysql", "root:123456@tcp(127.0.0.1:3306)/test?charset=utf8&parseTime=True&loc=Local")
	db.LogMode(true)
	//db.SetLogger(gorm.Logger{revel.TRACE})
	if err != nil {
		fmt.Println(err.Error())
	}
	if ok := db.HasTable(&model.User{}); ok {
		user := model.User{}
		user.Name = "asdfa"
		user.Age = 19
		user.Gender = "male"
		isPrimaryBlank := db.NewRecord(user)
		fmt.Println(isPrimaryBlank)
		db.Create(&user)
		isPrimaryBlank = db.NewRecord(user)
		fmt.Println(isPrimaryBlank)
	}

	defer db.Close()
}
